<?php
session_save_path('sessions');
session_start();

include("include/dbUserTypes.php");

// Include our user class
include_once("include/user.php");

// Create a variable to store our user if we're validated
$user = null;

// Check if we're in a valid session. If not, go back to main login page.

if( !isset($_SESSION['user']) || $_SESSION['user'] == null ) {
    header("location:main_login.php");
}
else {
    // Unserialize our user to turn it back into a useful object
    $user = unserialize($_SESSION['user']);
}

// If we're not a business (or admin) go back to the user redirection page
if( $user->getUserType() != $USERTYPE_REGISTERED && $user->getUserType() != $USERTYPE_ADMIN)
    header("location:login_success.php");


// Include the header (CSS files, etc)
include("include/dbconnection.php");
include("include/header.php"); ?>


<body>
  <div id="wrapper">
    <div id="header"> </div>
    <div id="left">
      <div id="logo">
        <h1>Home Sale</h1>
        <p>Only By Owner</p>
      </div>
      <div id="nav">
        <ul>
          <li >
            <a href="addAhomeForSale.php">Add a House for sale</a>
          </li>
          <li >
            <a href="updateAhome.php">Update House information</a>
          </li>
          <li >
            <a href="updateAhomePicture.php">Update House picture</a>
          </li>
          <li>
            <a href="searchhouse.php">Search House</a>
          </li>
          <li class="important">
            <a href="emailMenu.php">Mailbox</a>
          </li>
          <li>
            <a href="logout.php">Logout</a>
          </li>
        </ul>
      </div>
      <div id="news">
        <?php include("adgeneratorleft1.php");?>
        <div class="hr-dots"> </div>
        <?php include("adgeneratorleft2.php");?>
      </div>
      <div id="support">
      </div>
    </div>
    <div id="right">
      <h2>Outbox</h2>
      <div id="welcome">

        <?php

        $userID = $_POST["userID"];
        $senderID = $_POST["senderID"];
        $messageSubject = $_POST["messageSubject"];
        $messageContent = $_POST["messageContent"];

        $sql="INSERT INTO mailbox (userID, senderID, messageSubject, messageContent)
						VALUES('$userID', '$senderID', '$messageSubject', '$messageContent')";

			if (!mysql_query($sql))
			  {
			  die('Error: ' . mysql_error());
			  }

		$destinationNameQuery = mysql_query("select * from users where userID = $userID");
		$row2 = mysql_fetch_array($destinationNameQuery);
        $destinationName = $row2['username'];

		mysql_close();
        ?>

		<p>Message was sent successfully to <?php echo $destinationName?>!</p>


      </div>
      <h3></h3>
      <div id="profile">
        <div id="corp">
          <?php include("adgeneratorbottomleft.php");?>
        </div>
        <div id="indu">
          <?php include("adgeneratorbottomright.php");?>
        </div>
      </div>
    </div>
    <div class="clear"> </div>
    <div id="spacer"> </div>
    <div id="footer">
      <div id="copyright">
        &copy; Template taken from http://www.freewebsitetemplates.com/
      </div>
      <div id="footerline"></div>
    </div>

  </div>
</body>